package com.xzy.generic;

import com.xzy.simple.User;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.ApplicationContext;

/**
 * {@link GenericEvent} 事件发布器
 *
 * @author xzy.xiao
 * @date 2023/2/27  9:43
 */
public class GenericEventPublisher {
    private static final Logger logger = LoggerFactory.getLogger(GenericEventPublisher.class);

    public static void sendUserInsertEvent(ApplicationContext applicationContext) {
        GenericEvent<User> genericEvent = new GenericEvent<>(GenericEventPublisher.class, GenericEvent.EventType.INSERT, new User(1000L, "张三"));
        logger.info("发布事件：{}", genericEvent);
        applicationContext.publishEvent(genericEvent);
    }

    public static void sendLoginInsertEvent(ApplicationContext applicationContext) {
        GenericEvent<Login> genericEvent = new GenericEvent<>(GenericEventPublisher.class, GenericEvent.EventType.INSERT, new Login(1000L, System.currentTimeMillis()));
        logger.info("发布事件：{}", genericEvent);
        applicationContext.publishEvent(genericEvent);
    }
}
